package com.culturalCenter.dataCenter.mapper.user;

import com.culturalCenter.dataCenter.entity.user.UserPoint;
import com.culturalCenter.dataCenter.mapper.base.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface UserPointMapper extends BaseMapper<UserPoint> {

    /**
     * 通过用户id查询
     *
     * @param userId 用户id
     *
     * @return
     */
    List<UserPoint> queryByUserId(@Param("userId") String userId);

    /**
     * 查询当前页需要的日期
     *
     * @param offset
     * @param pageSize
     *
     * @return
     */
    @Select("SELECT DATE_FORMAT(createTime,'%Y-%m-%d') time FROM cdc_user_point GROUP BY time ORDER BY time DESC LIMIT #{offset}, #{pageSize}")
    List<String> findDateList(@Param("offset") int offset, @Param("pageSize") int pageSize);

    /**
     * 根据用户和日期查询
     *
     * @param userId
     * @param date
     *
     * @return
     */
    @Select("SELECT * FROM cdc_user_point WHERE userId = #{userId} AND DATE_FORMAT(createTime,'%Y-%m-%d') = #{date}")
    List<UserPoint> findListByUserAndDate(@Param("userId") String userId, @Param("date") String date);

    long finDateCount();

}
